package com.poetry.controller.common;

import com.poetry.domain.po.Poem;
import com.poetry.exception.BasePage;
import com.poetry.exception.R;
import com.poetry.service.IPoemService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "诗词管理模块")
@RestController("/poem")
public class PoemController {
    @Resource
    private IPoemService poemService;

    @PostMapping("/search_poem_page")
    @Operation(summary = "诗词分页和条件查询")
    public R<List<Poem>> searchPoemPage(@RequestBody BasePage basePage) {
        return poemService.searchPoemPage(basePage);
    }

    @GetMapping("/query/{id}")
    @Operation(summary = "获取诗词详情")
    public R<Poem> queryPoemById(@PathVariable("id") Integer id) {
        return poemService.queryById(id);
    }

    @PutMapping("/like/{id}")
    @Operation(summary = "收藏诗词")
    public R<String> likePoem(@PathVariable("id") Integer id) {
        return poemService.likePoem(id);
    }

    @GetMapping("/query_liked")
    @Operation(summary = "查看收藏")
    public R<List<Poem>> queryLikedPoem() {
        return poemService.queryLikedPoem();
    }

}
